<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>殡葬服务机构墓位信息公示</title>
  <script src="https://cdn.tailwindcss.com"></script>
  <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
  
  <!-- Tailwind 配置 -->
  <script>
    tailwind.config = {
      theme: {
        extend: {
          colors: {
            primary: '#1e3a8a',      // 深蓝主色调，体现庄重专业
            secondary: '#475569',    // 灰色辅助色
            available: '#10b981',    // 未售墓位-绿色
            sold: '#ef4444',         // 已售墓位-红色
            neutral: '#f3f4f6',      // 中性背景色
          },
          fontFamily: {
            sans: ['Inter', 'system-ui', 'sans-serif'],
          },
        },
      }
    }
  </script>
  
  <style type="text/tailwindcss">
    @layer utilities {
      .tomb-grid {
        display: grid;
        grid-template-columns: repeat(11, minmax(0, 1fr));
        gap: 2px;
      }
      .tomb-cell {
        aspect-ratio: 1/1;
        cursor: pointer;
        transition: all 0.2s ease;
      }
      .tomb-cell:hover {
        transform: scale(1.1);
        z-index: 10;
      }
      .scrollbar-thin {
        scrollbar-width: thin;
      }
      .scrollbar-thin::-webkit-scrollbar {
        width: 6px;
        height: 6px;
      }
      .scrollbar-thin::-webkit-scrollbar-thumb {
        background-color: rgba(156, 163, 175, 0.5);
        border-radius: 3px;
      }
    }
  </style>
</head>
<body >
    <!-- 墓位可视化区域 -->
    <section class="bg-white rounded-lg shadow-md p-6">
      <div class="flex justify-between items-center mb-6">
        <h2 class="text-xl font-semibold text-primary">
          <span id="display-cemetery">怀恩楼G1-A（一楼1号房A排）</span> 墓位分布
        </h2>
        <div class="text-sm text-gray-500">
          点击墓位可查看详情
        </div>
      </div>
      
      <!-- 网格容器 - 带滚动条以适应小屏幕 -->
      <div class="overflow-auto scrollbar-thin border border-gray-200 rounded-md p-4 min-h-[500px]">
        <!-- 行号标题 -->
        <div class="flex mb-2">
          <div class="w-8 text-center font-medium text-gray-500">列\行</div>
          <div class="flex-1 flex">
            <!-- 列号 -->
            <div class="tomb-grid w-full">
              <!-- 生成1-20列号 -->
              <script>
                for (let i = 1; i <= 11; i++) {
                  document.write(`<div class="flex items-center justify-center text-xs font-medium text-gray-500">${i}</div>`);
                }
              </script>
            </div>
          </div>
        </div>
        
        <!-- 墓位网格 -->
        <div id="tomb-grid-container">
          <!-- 生成20行，每行20个墓位 -->
          <script>
            for (let row = 1; row <= 6; row++) {
              document.write(`
                <div class="flex mb-2">
                  <div class="w-8 flex items-center justify-center text-xs font-medium text-gray-500 mr-2">${row}</div>
                  <div class="tomb-grid w-full">
              `);
              
              // 为每行生成20个墓位
              for (let col = 1; col <= 11; col++) {
                // 随机生成已售/未售状态 (约40%已售)
                const isSold = Math.random() < 0.4;
                const statusClass = isSold ? 'bg-sold' : 'bg-available';
                const statusText = isSold ? '已售' : '未售';
                
                document.write(`
                  <div class="tomb-cell ${statusClass} rounded-sm" 
                       data-row="${row}" 
                       data-col="${col}"
                       data-status="${isSold ? 'sold' : 'available'}"
                       title="${statusText} (${row}行${col}列)">
                  </div>
                `);
              }
              
              document.write(`
                  </div>
                </div>
              `);
            }
          </script>
        </div>
      </div>
    </section>
  </main>

  <!-- 墓位详情模态框 -->
  <div id="tomb-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
    <div class="bg-white rounded-lg shadow-xl max-w-md w-full mx-4 transform transition-all">
      <div class="p-6 border-b border-gray-200">
        <div class="flex justify-between items-center">
          <h3 class="text-lg font-semibold text-gray-900" id="modal-title">墓位详情</h3>
          <button id="close-modal" class="text-gray-400 hover:text-gray-500">
            <i class="fa fa-times"></i>
          </button>
        </div>
      </div>
      <div class="p-6">
        <div class="space-y-4">
          <div>
            <p class="text-sm text-gray-500">位置信息</p>
            <p class="font-medium" id="tomb-location">中山福荫园 - A区 (5行8列)</p>
          </div>
          <div>
            <p class="text-sm text-gray-500">状态</p>
            <p class="font-medium" id="tomb-status">已售</p>
          </div>
          <div id="sold-details" class="hidden">
            <div>
              <p class="text-sm text-gray-500">售出日期</p>
              <p class="font-medium" id="sale-date">2023-05-18</p>
            </div>
            <div>
              <p class="text-sm text-gray-500">使用期限</p>
              <p class="font-medium">长期</p>
            </div>
          </div>
          <div id="available-details">
            <div>
              <p class="text-sm text-gray-500">价格</p>
              <p class="font-medium" id="tomb-price">¥38,000</p>
            </div>
            <div>
              <p class="text-sm text-gray-500">面积</p>
              <p class="font-medium">1.2平方米</p>
            </div>
          </div>
        </div>
      </div>
      <div class="px-6 py-4 bg-gray-50 rounded-b-lg flex justify-end">
        <button id="modal-close-btn" class="px-4 py-2 bg-gray-200 text-gray-800 rounded-md hover:bg-gray-300 transition-colors">
          关闭
        </button>
      </div>
    </div>
  </div>

  <!-- 页脚 -->
  <footer class="bg-secondary text-white mt-12">
    <div class="container mx-auto px-4 py-8">
      <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
        <div>
          <h3 class="text-lg font-semibold mb-4">关于系统</h3>
          <p class="text-sm opacity-80">本系统公示各殡葬服务机构墓位信息，方便公众查询了解墓位销售状态，促进殡葬服务透明化。</p>
        </div>
        <div>
          <h3 class="text-lg font-semibold mb-4">联系我们</h3>
          <p class="text-sm opacity-80 flex items-center mb-2">
            <i class="fa fa-phone mr-2"></i> 服务热线：400-123-4567
          </p>
          <p class="text-sm opacity-80 flex items-center">
            <i class="fa fa-envelope mr-2"></i> 邮箱：service@cemetery-info.com
          </p>
        </div>
        <div>
          <h3 class="text-lg font-semibold mb-4">服务时间</h3>
          <p class="text-sm opacity-80">周一至周五：9:00 - 17:00</p>
          <p class="text-sm opacity-80">周六至周日：9:00 - 16:00</p>
          <p class="text-sm opacity-80">法定节假日另行通知</p>
        </div>
      </div>
      <div class="border-t border-gray-600 mt-8 pt-6 text-center text-sm opacity-70">
        <p>© 2023 殡葬服务机构墓位信息公示系统 版权所有</p>
      </div>
    </div>
  </footer>

  <script>
    // 设置当前日期
    document.addEventListener('DOMContentLoaded', function() {
      // 绑定事件
      // bindEvents();
      
      // 计算并更新统计数据
      // updateStatistics();
    });
    
    // 绑定事件处理
    function bindEvents() {
      // 机构和区域选择变化时更新显示
      document.getElementById('cemetery').addEventListener('change', function() {
        const cemeteryNames = {
          'fuyinyuan': '中山福荫园',
          'wanfuyuan': '万福园',
          'qingmingyuan': '清明园',
          'shengyuan': '圣园公墓'
        };
        document.getElementById('display-cemetery').textContent = cemeteryNames[this.value];
        refreshTombGrid();
      });
      
      document.getElementById('area').addEventListener('change', function() {
        document.getElementById('display-area').textContent = this.value.toUpperCase() + '区';
        refreshTombGrid();
      });
      
      // 刷新按钮
      document.getElementById('refresh-btn').addEventListener('click', function() {
        refreshTombGrid();
        // 添加刷新动画
        this.classList.add('animate-spin');
        setTimeout(() => {
          this.classList.remove('animate-spin');
        }, 500);
      });
      
      // 墓位点击事件
      document.querySelectorAll('.tomb-cell').forEach(cell => {
        cell.addEventListener('click', function() {
          showTombDetails(this);
        });
      });
      
      // 关闭模态框
      document.getElementById('close-modal').addEventListener('click', closeModal);
      document.getElementById('modal-close-btn').addEventListener('click', closeModal);
      
      // 点击模态框外部关闭
      document.getElementById('tomb-modal').addEventListener('click', function(e) {
        if (e.target === this) {
          closeModal();
        }
      });
    }
    
    // 刷新墓位网格数据
    function refreshTombGrid() {
      document.querySelectorAll('.tomb-cell').forEach(cell => {
        // 随机重新生成状态，保持约40%的已售率，但不完全相同
        const isSold = Math.random() < 0.4;
        const statusClass = isSold ? 'bg-sold' : 'bg-available';
        const statusText = isSold ? '已售' : '未售';
        
        // 移除旧状态类
        cell.classList.remove('bg-sold', 'bg-available');
        // 添加新状态类
        cell.classList.add(statusClass);
        // 更新数据属性
        cell.dataset.status = isSold ? 'sold' : 'available';
        cell.title = `${statusText} (${cell.dataset.row}行${cell.dataset.col}列)`;
      });
      
      // 更新统计数据
      updateStatistics();
    }
    
    // 更新统计数据
    function updateStatistics() {
      const total = 400;
      const sold = document.querySelectorAll('.tomb-cell[data-status="sold"]').length;
      const available = total - sold;
      
      document.getElementById('sold-count').textContent = sold;
      document.getElementById('available-count').textContent = available;
    }
    
    // 显示墓位详情
    function showTombDetails(cell) {
      const row = cell.dataset.row;
      const col = cell.dataset.col;
      const status = cell.dataset.status;
      const isSold = status === 'sold';
      
      const cemetery = document.getElementById('display-cemetery').textContent;
      const area = document.getElementById('display-area').textContent;
      
      // 更新模态框内容
      document.getElementById('tomb-location').textContent = `${cemetery} - ${area} (${row}行${col}列)`;
      document.getElementById('tomb-status').textContent = isSold ? '已售' : '未售';
      document.getElementById('tomb-status').className = isSold ? 'font-medium text-sold' : 'font-medium text-available';
      
      // 显示/隐藏不同状态的详情
      document.getElementById('sold-details').classList.toggle('hidden', !isSold);
      document.getElementById('available-details').classList.toggle('hidden', isSold);
      
      // 随机生成价格（30000-60000之间，步长1000）
      const price = Math.floor(Math.random() * 31) * 1000 + 30000;
      document.getElementById('tomb-price').textContent = `¥${price.toLocaleString()}`;
      
      // 随机生成售出日期（过去1-3年）
      const today = new Date();
      const saleDate = new Date(today.setFullYear(today.getFullYear() - Math.floor(Math.random() * 3) - 1));
      const saleDateStr = `${saleDate.getFullYear()}-${String(saleDate.getMonth() + 1).padStart(2, '0')}-${String(saleDate.getDate()).padStart(2, '0')}`;
      document.getElementById('sale-date').textContent = saleDateStr;
      
      // 显示模态框
      document.getElementById('tomb-modal').classList.remove('hidden');
      // 添加动画效果
      const modalContent = document.getElementById('tomb-modal').querySelector('div');
      modalContent.classList.add('scale-95', 'opacity-0');
      setTimeout(() => {
        modalContent.classList.remove('scale-95', 'opacity-0');
        modalContent.classList.add('scale-100', 'opacity-100', 'transition-all', 'duration-300');
      }, 10);
    }
    
    // 关闭模态框
    function closeModal() {
      const modal = document.getElementById('tomb-modal');
      const modalContent = modal.querySelector('div');
      
      // 添加退出动画
      modalContent.classList.remove('scale-100', 'opacity-100');
      modalContent.classList.add('scale-95', 'opacity-0', 'transition-all', 'duration-300');
      
      setTimeout(() => {
        modal.classList.add('hidden');
        modalContent.classList.remove('scale-95', 'opacity-0', 'transition-all', 'duration-300');
      }, 300);
    }


  window.onload = function() {
    window.parent.postMessage({height: document.body.scrollHeight}, '*'); // 发送消息到父页面，'*' 是目标来源，可以根据需要更改为具体域名以增加安全性。
  };

  </script>
</body>
</html>
